package com.yixia.system.mapper.system;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yixia.system.domain.system.SysRoleMenu;
import org.apache.ibatis.annotations.Mapper;

import java.util.ArrayList;
import java.util.List;

/**
* @author 35038
* @description 针对表【sys_role_menu】的数据库操作Mapper
* @createDate 2023-06-02 19:15:12
* @Entity com.java1234.entity.SysRoleMenu
*/
@Mapper
public interface SysRoleMenuMapper extends BaseMapper<SysRoleMenu> {

    /**
     * 将角色菜单信息进行插入---批量插入
     * @param list
     * @return
     */
    default int batchRoleMenu(List<SysRoleMenu> list){
        int rows = 1;
        for (SysRoleMenu sysRoleMenu : list) {
            rows = rows + this.insert(sysRoleMenu);
        }
        return rows;
    }

    /**
     * 根据角色ID来获取角色菜单集合
     * @param roleId
     * @return
     */
    default List<SysRoleMenu> selectByRoleId(Long roleId){
        LambdaQueryWrapper<SysRoleMenu> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SysRoleMenu::getRoleId, roleId);
        List<SysRoleMenu> list = this.selectList(queryWrapper);
        return list;
    }

    /**
     * 根据RoleId来删除角色菜单表中的信息
     * @param roleId
     */
    default boolean deleteRoleMenuByRoleId(Long roleId){
        LambdaQueryWrapper<SysRoleMenu> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SysRoleMenu::getRoleId, roleId);
        int rows = this.delete(queryWrapper);
        return rows > 0;
    }

    /**
     * 根据RoleId来删除角色菜单表中的信息
     * @param roleIds
     */
    default int deleteRoleMenuByRoleIds(Long[] roleIds){
        LambdaQueryWrapper<SysRoleMenu> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.in(SysRoleMenu::getRoleId, roleIds);
        int rows = this.delete(queryWrapper);
        return rows;
    }

    /**
     * 根据角色ID查询菜单ID
     * @param roleIds
     * @return
     */
    default List<SysRoleMenu> selectByRoleIds(List<Long> roleIds){
        if(roleIds.size() == 0){
            return new ArrayList<>();
        }
        LambdaQueryWrapper<SysRoleMenu> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.in(SysRoleMenu::getRoleId, roleIds);
        return this.selectList(queryWrapper);
    }
}




